//
//  JieSuanViewController.m
//  EJLX
//
//  Created by xufei on 15/12/16.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "JieSuanViewController.h"

@interface JieSuanViewController ()

@end

@implementation JieSuanViewController


-(void)viewWillAppear:(BOOL)animated
{
//    [HttpsManager requestJieSuan:_accountId comoletion:^(JieSuanShuJu *jieSuan)
//    {
//        _jieSuan=jieSuan;
//        [self bigView];
//    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor=RGB(240, 240, 240);
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 20,WIDE , 44)];
    view.backgroundColor=RGB_COLOR(0x00c49f);
    [self.view addSubview:view];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(WIDE/2-35, 10, 70, 24)];
    label.text=@"申请结算";
    label.textColor=[UIColor whiteColor];
    [view addSubview:label];
    UIButton*but1=[[UIButton alloc]initWithFrame:CGRectMake(10,7,30,30)];
    [but1 setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal];
    [but1 addTarget:self action:@selector(butClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:but1];
    [HttpsManager requestJieSuan:_accountId comoletion:^(JieSuanShuJu *jieSuan)
     {
         if (jieSuan!=nil)
         {
             _jieSuan=jieSuan;
             [self bigView];
         }
         else
         {
             LoginVC*vc=[[LoginVC alloc]init];
             [self.navigationController pushViewController:vc animated:YES];
         }
        
     }];
    //[self bigView];
}
-(void)bigView
{
    
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10, WIDE, 70)];
    view1.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view1];
    UIImageView*picture=[[UIImageView alloc]initWithFrame:CGRectMake(2, 5, 60, 60)];
    [view1 addSubview:picture];
    UILabel*nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(65, 5,200, 30)];
    nameLabel.font=[UIFont systemFontOfSize:12];
    nameLabel.textColor=[UIColor blackColor];
    nameLabel.text=_jieSuan.bankName;
    [view1 addSubview:nameLabel];
    UILabel*kaHaoLabel=[[UILabel alloc]initWithFrame:CGRectMake(65,40,200, 30)];
    kaHaoLabel.font=[UIFont systemFontOfSize:12];
    kaHaoLabel.textColor=[UIColor blackColor];
    kaHaoLabel.text=_jieSuan.bankCode;
    [view1 addSubview:kaHaoLabel];
    UIView*view2=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10+70+10, WIDE,40)];
    view2.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view2];
    UILabel*keLabel=[[UILabel alloc]initWithFrame:CGRectMake(2, 5,100, 30)];
    keLabel.font=[UIFont systemFontOfSize:15];
    keLabel.textColor=[UIColor blackColor];
    keLabel.text=@"可结算金额:";
    [view2 addSubview:keLabel];
    UILabel*moneyLabel=[[UILabel alloc]initWithFrame:CGRectMake(120, 5,100, 30)];
    moneyLabel.font=[UIFont systemFontOfSize:15];
    moneyLabel.textColor=[UIColor blackColor];
    moneyLabel.text=[NSString stringWithFormat:@"%.2f",_jieSuan.amount*0.01];
    [view2 addSubview:moneyLabel];
    UIView*view3=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10+70+10+40+1, WIDE,40)];
    view3.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view3];
    UILabel*jieSuanLabel=[[UILabel alloc]initWithFrame:CGRectMake(2, 5,100, 30)];
    jieSuanLabel.font=[UIFont systemFontOfSize:15];
    jieSuanLabel.textColor=[UIColor blackColor];
    jieSuanLabel.text=@"结算金额:";
    [view3 addSubview:jieSuanLabel];
    field=[[UITextField alloc]initWithFrame:CGRectMake(120, 5,120, 30)];
    field.placeholder=@"请输入金额";
    field.delegate=self;
   
    [view3 addSubview:field];
    UIView*view4=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10+70+10+40+1+40+1, WIDE,40)];
    view4.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view4];
    UILabel*shiJiLabel=[[UILabel alloc]initWithFrame:CGRectMake(2, 5,100, 30)];
    shiJiLabel.font=[UIFont systemFontOfSize:15];
    shiJiLabel.textColor=[UIColor blackColor];
    shiJiLabel.text=@"实际扣除金额:";
    [view4 addSubview:shiJiLabel];
    UILabel*shiMoneyLabel=[[UILabel alloc]initWithFrame:CGRectMake(120, 5,100, 30)];
    shiMoneyLabel.font=[UIFont systemFontOfSize:15];
    shiMoneyLabel.textColor=[UIColor blackColor];
    shiMoneyLabel.text=[NSString stringWithFormat:@"%.2f",_jieSuan.fee*0.01];
    [view4 addSubview:shiMoneyLabel];
    
    UILabel*tiShi=[[UILabel alloc]initWithFrame:CGRectMake(2, 64+10+70+10+40+1+40+1+50, 60, 30)];
    tiShi.text=@"温馨提示:";
    tiShi.textColor=[UIColor redColor];
    tiShi.font=[UIFont systemFontOfSize:13];
    [self.view addSubview:tiShi];
    UILabel*feiYong=[[UILabel alloc]initWithFrame:CGRectMake(2+60+5, 64+10+70+10+40+1+40+1+50,200, 30)];
    feiYong.textColor=[UIColor blackColor];
    feiYong.font=[UIFont systemFontOfSize:12];
    feiYong.text=[NSString stringWithFormat:@"您的结算费用为%.2f元",_jieSuan.fee*0.01];
    [self.view addSubview:feiYong];
    UILabel*pT=[[UILabel alloc]initWithFrame:CGRectMake(2+60+5, 64+10+70+10+40+1+40+50+1+35, 60, 30)];
    pT.textColor=[UIColor blackColor];
    pT.font=[UIFont systemFontOfSize:12];
    pT.text=@"普通结算";
    [self.view addSubview:pT];
    UIButton*jieSuanBut=[[UIButton alloc]initWithFrame:CGRectMake(100,64+10+70+10+40+1+40+50+1+35+30+5, WIDE-200, 30)];
    jieSuanBut.backgroundColor=RGB_COLOR(0x00c49f);
    [jieSuanBut setTitle:@"结算" forState:UIControlStateNormal];
    [jieSuanBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [jieSuanBut addTarget:self action:@selector(jieSuanButClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:jieSuanBut];

    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSUInteger lengthOfString = string.length;
    for (NSInteger loopIndex = 0; loopIndex < lengthOfString; loopIndex++) {//只允许数字输入
        unichar character = [string characterAtIndex:loopIndex];
        if (character < 48) return NO; // 48 unichar for 0
        if (character > 57) return NO; // 57 unichar for 9
    }
    // Check for total length
    NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
    if (proposedNewLength > 100) return NO;//限制长度
    return YES;
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)jieSuanButClick
{
    float a=[field.text intValue];
    int b=a*100;
    
    [HttpsManager requestJieSuanAnNiu:_accountId amont:[NSString stringWithFormat:@"%d",b] comoletion:^(NSString *errmsg, int errcode, NSString *walletId, NSString *amount)
    {
        if (errcode==0)
        {
            SHOW_ALERT(errmsg);
        }
        else
        {
            SHOW_ALERT(errmsg);
        }
    }];
}
-(void)butClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
